package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.BlackList;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.mapper.BlackListMapper;
import com.itheima.service.db.BlackListService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author 请不要叫我高司令
 * @Date 2022/3/16 0:50
 * @Version 1.0
 */

@DubboService
public class BlackListServiceImpl implements BlackListService {


    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public PageBeanVo findByPage(Long userId, Integer pageNum, Integer pageSize) {
        // 1.开启分页
        Page<BlackList> page = new Page(pageNum, pageSize);
        // 2.构建条件
        LambdaQueryWrapper<BlackList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BlackList::getUserId, userId);
        // 3.分页查询
        page = blackListMapper.selectPage(page, queryWrapper);
        // 4.封装pageBeanVo
        return new PageBeanVo(pageNum, pageSize, page.getTotal(), page.getRecords());
    }

    @Override
    public void delete(Long userId, Long blackUserId) {

        LambdaQueryWrapper<BlackList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BlackList::getBlackUserId, blackUserId)
        .eq(BlackList::getUserId,userId);

        blackListMapper.delete(queryWrapper);

    }


}
